
#include "App_PowerStapler.h"
#include <pic18f6722.h>


//********************************************************************
/* Initialize interrupt
 * input:  void
 * return: void
 * author: Guichuan.He
 * date: 2016-9-28
*/ 
//********************************************************************** 
void App_Interrupt_Initialize(void)       // TMR0 initialization 
{ 
    INTCON  = 0XE0;  //GIE = 1; PEIC = 1; TMR0IE = 1
    T0CON = 0X80;
    
    INTEDG1 = 0; //Interrupt on FALL edge
    INTEDG0 = 0; //Interrupt on FALL edge   
    INT1E = 1;  //INT1 External Interrupt Enable bit
    INT0E = 1;  //INT2 External Interrupt Enable bit
 }  

//********************************************************************
/* timer interrupt
 * input:  void
 * return: void
 * author: Guichuan.He
 * date: 2016-9-28
*/
//********************************************************************** 
int led_flag=0;
unsigned int time_count1=0;
void set_time_count(unsigned int time)
{
    time_count1=time;
}

unsigned int get_time_count(void)
{
    return time_count1;
}
void interrupt timer(void)
{
   if(TMR0IF)
    {
        TMR0IF = 0;
        TMR0L = 0x56;
        TMR0H = 0x45;
      
        PowerStaplerData.Timer.Work_LED_Count++;
        if( PowerStaplerData.Timer.Work_LED_Count == 2 )
        {
             //Work_LED = ~ Work_LED;
#if 0
            if(led_flag==0)
            {
               Work_LED = ~ Work_LED;
                led_flag=1;
            }
          
#endif
            PowerStaplerData.Timer.Work_LED_Count = 0;  
//           if (LED_Flash == 1) 
//           {
//              Device_Indicator_SetLED(4);
//           }
//           if (LED_Flash == 2) 
//           {
//               Device_Indicator_SetLED(5);
//           }
            if(work_led_flag==1)
            {
               Device_Indicator_SetLED(4); 
//               work_led_flag=0;
            }
            else if(work_led_flag==2)
            {
              Device_Indicator_SetLED(1);
//              work_led_flag=0;
            }
            else
            {
                work_led_flag=0;
            }
         
        }
        
        timecounter++;
        timecouner_dicharge++;
        timecouner_charge++;
        timecouner_fullcharge++;
        time_count1++;   
    }
  /*
   if( RB0 == 0)
   {
       LED_Flash = 2;
       Device_Indicator_SetLED(2);
   }
   else 
   {
        LED_Flash = 0;
   }
 */      
       
   
   
    if(INT1IF)
    {
       INT1IF = 0;
       Device_MotorOutControl(0);
    }
   
   
   if(INT0IF)
   {
       INT0IF = 0;
       Device_MotorOutControl(0);
       Device_Indicator_SetLED(2); //green
   }
   
}
    

